package br.edu.universo.si.projeto2.infojob.client.apresentacao;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;

/*
 * Caixa de Login
 */
public class ALogin extends DockPanel
{
	private static final String TAMANHO_CAMPOS = "150";
	private static final int MAXIMO_CARACTERES = 40;
	
	private HorizontalPanel rodape;

	private DecoratorPanel formularioPanel;
	private FlexTable flexTable;
	private FlexCellFormatter cellFormatter;

	private TextBox loginTxtBox;
	private PasswordTextBox senhaTxtBox;

	private Button logonBtn;
	private Button limparBtn;

	public ALogin()
	{
		formularioPanel = new DecoratorPanel();

		rodape = new HorizontalPanel();
		rodape.setSpacing(3);

		loginTxtBox = new TextBox();
		senhaTxtBox = new PasswordTextBox();
		
		loginTxtBox.setWidth(TAMANHO_CAMPOS);
		senhaTxtBox.setWidth(TAMANHO_CAMPOS);
		
		loginTxtBox.setMaxLength(MAXIMO_CARACTERES);
		senhaTxtBox.setMaxLength(MAXIMO_CARACTERES);
		
		// botao para limpar o conteudo dos campos
		limparBtn = new Button("Limpar");
		limparBtn.addClickListener(
			new ClickListener()
			{
				public void onClick(Widget sender)
				{
					// limpa o conteudo dos campos
					loginTxtBox.setText("");
					senhaTxtBox.setText("");
				}
			}
		);

		// botao para logar no sistema
		logonBtn = new Button("Login");

		flexTable = new FlexTable();
		flexTable.setCellPadding(5);

		cellFormatter = flexTable.getFlexCellFormatter();
		cellFormatter.setColSpan(0, 0, 2);

		flexTable.setHTML(0, 0, "Entre com os dados de sua conta:");

		flexTable.setHTML(1, 0, "Login: ");
		cellFormatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);

		flexTable.setHTML(2, 0, "Senha: ");
		cellFormatter.setAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);

		flexTable.setWidget(1, 1, loginTxtBox);
		flexTable.setWidget(2, 1, senhaTxtBox);

		rodape.add(logonBtn);
		rodape.add(limparBtn);

		flexTable.setWidget(3, 0, rodape);
		flexTable.getFlexCellFormatter().setColSpan(3, 0, 2);
		flexTable.getFlexCellFormatter().setAlignment(3, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);

		formularioPanel.add(flexTable);

		this.add(formularioPanel, DockPanel.CENTER);
	}

	public TextBox getLoginTxtBox() {
		return loginTxtBox;
	}

	public void setLoginTxtBox(TextBox loginTxtBox) {
		this.loginTxtBox = loginTxtBox;
	}

	public PasswordTextBox getSenhaTxtBox() {
		return senhaTxtBox;
	}

	public void setSenhaTxtBox(PasswordTextBox senhaTxtBox) {
		this.senhaTxtBox = senhaTxtBox;
	}

	public Button getLogonBtn() {
		return logonBtn;
	}

	public void setLogonBtn(Button logonBtn) {
		this.logonBtn = logonBtn;
	}

}